//外层引入config让配置的路径名生效
require(['./config'],()=>{
	//boostrap没有返回值
	require(['swiper','template','header','footer','bootstrap'],(Swiper,template)=>{
		class Index{
			constructor() {
			    this.banner()
				this.getData()
				this.getBannerData()
				this.getSmallPic()
				this.getDoubleCart()
				this.getoneCart()
				// console.dir($)
			}
			// 轮播图
			banner(){
				 var swiper = new Swiper('.swiper-container', {
				      spaceBetween: 30,
				      centeredSlides: true,
				      autoplay: {
				        delay: 5000,
				        disableOnInteraction: false,
				      },
				      pagination: {
				        el: '.swiper-pagination',
				        clickable:true,
				      },
				      navigation: {
				        nextEl: '.swiper-button-next',
				        prevEl: '.swiper-button-prev',
				      },
				    });
				new Swiper()
			}
			getData(){
				const baseUrl='http://rap2api.taobao.org/app/mock/268441'
				$.ajax({
					url:baseUrl+'/api/shoplist',
					method:'get',
					 // data:{id,img,title},
					success:resp=>{
						if(resp.code===200){
							// console.log(resp.body)
							const {list} =resp.body
								let str='';
								let str2='';
								list.forEach((shop,index) =>{
								str+=
										`
				
					
												<dl>
													<dt><img src="${shop.img}" ></dt>
													<dd>
														<a href="#"><p>${shop.title}</p></a>
														<i>${shop.describe}</i>
													</dd>
												</dl>
											
										`
								str2+=
										`
																						
																							
										<dl>
										<dt><img src="${shop.img}" ></dt>
										<dd>
											<a href="#"><p>${shop.title}</p></a>
												<i>${shop.describe}</i>
										</dd>
										</dl>
															
														`
								})
								$('.brandstory-content-middle-left').html(str)
								$('.brandstory-content-middle-m').html(str2)
							
						}
					},
					dataType:'json'
				})
			}
			//Json获取轮播图
		getBannerData(){
			$.get('/libs/json/bannerjson.json',resp=>{
				// 第一个参数传入模版id，模板里需要的属性
				// console.log(resp)
				const html=template('bannerTemplate',{
					list:resp
				})
				// console.log(html)
				$('#bigswiper').html(html)
				})
			}
			getSmallPic(){
				$.get('http://rap2api.taobao.org/app/mock/268441/api/smallbanner',resp=>{
					if(resp.code===200){
						// console.log(resp)
						const {title,des,kinds,photo} =resp.body
						
						// console.log(photo)
						$('#shop').html(template('shopTemplate',{
							title,
							des,
							kinds,
							photo
							// console.log(html)
							}))
					}
				})
			}
			
		//获取双卡片数据
		getDoubleCart(){
			$.get('/libs/json/doublecart.json',resp=>{
				// console.log(resp)
				// const[list,list1]=resp
				// const{list}=resp[0]
				// console.log(list)
				// // console.log(list,list1)
				const html=template('doublecardtopTemplate',{
					resp
					// list1:resp[1]
				})
				// console.log(html)
				$('#doublecardtop').html(html)
			})
			}
		//获取单卡片数据
		getoneCart(){
			$.get('http://rap2api.taobao.org/app/mock/268441/api/onecart',resp=>{
				// console.log(resp)
				const{body}=resp
				// console.log(body)
				const html=template('seriesTemplate',{body
				})
				// console.log(html)
				$('#series').html(html)
			})
			}
		}
		new Index()
	})
})

